package com.summer.campussct.controller;

import com.summer.campussct.annotation.Permission;
import com.summer.campussct.pojo.Banner;
import com.summer.campussct.pojo.dto.RestResult;
import com.summer.campussct.service.IBannerService;
import com.summer.campussct.utils.PermissionConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api("轮播图API")
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Resource
    private IBannerService bannerService;

    @ApiOperation("获取轮播图API")
    @GetMapping("list")
    public RestResult getHomeBanner(@RequestParam(required = false) Integer categoryId,
                                    @RequestParam(required = false) Integer campusOrShopType){
        return bannerService.getBannerByCategoryId(categoryId, campusOrShopType);
    }

    @ApiOperation("新增轮播图")
    @PostMapping("add")
    @Permission(PermissionConstant.BANNER)
    public RestResult addBanner(@RequestBody @Validated Banner banner) {
        return bannerService.addBanner(banner);
    }

    @ApiOperation("修改轮播图")
    @PutMapping("modify")
    @Permission(PermissionConstant.BANNER)
    public RestResult modifyBanner(@RequestBody @Validated Banner banner) {
        return bannerService.modifyBanner(banner);
    }

    @ApiOperation("根据id删除banner")
    @DeleteMapping("delete/{id}")
    @Permission(PermissionConstant.BANNER)
    public RestResult deleteBanner(@PathVariable("id") long id){
        return bannerService.deleteBanner(id);
    }

}
